package com.bgds.sys.config.socket;

import com.bgds.sys.common.constant.SocketConstant;
import com.bgds.sys.common.pagevo.DynamicAttrVo;
import com.bgds.sys.common.pagevo.RollerAttr;
import com.bgds.sys.common.pagevo.RollerVo;
import com.bgds.sys.common.utils.ResultUtil;
import com.bgds.sys.module.entity.Device;
import com.bgds.sys.module.entity.DeviceDynamicAttr;
import com.bgds.sys.module.entity.dto.AlarmInfo;
import com.bgds.sys.module.service.IAlarmLogService;
import com.bgds.sys.module.service.IDeviceDynamicAttrService;
import com.bgds.sys.module.service.IDeviceService;
import com.bgds.sys.task.CronSchedulerJob;
import lombok.extern.slf4j.Slf4j;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;


/**
 * @Description
 * @Author lj
 * @create: 2020-07-10 13:43
 */
@Controller
@Slf4j
public class WebSocketStompController {


    @Autowired
    private IAlarmLogService iAlarmLogService;
    @Autowired
    private IDeviceDynamicAttrService deviceDynamicAttrService;
    @Autowired
    private SimpMessagingTemplate messagingTemplate;

    @Autowired
    private IDeviceService deviceService;
    @Autowired
    private CronSchedulerJob cronSchedulerJob;


    /**
     * 助燃风机页面设备状态推送
     *
     * @return
     */

    @MessageMapping("/combustion_support_fan/{relationId}/{deviceCode}/{id}")
    public void combSupportFan(@DestinationVariable(value = "relationId") String relationId,@DestinationVariable(value = "deviceCode") String deviceCode, @DestinationVariable(value = "id") String id) {
        try {
            cronSchedulerJob.startCombustionSupportFanTask(relationId,deviceCode, id);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    /**
     * 除鳞泵页面设备状态推送
     *
     * @return
     */

    @MessageMapping("/discaling_pump/{deviceCode}/{id}")
    public void discalingPump(@DestinationVariable(value = "deviceCode") String deviceCode, @DestinationVariable(value = "id") String id) {
        try {
            cronSchedulerJob.startDiscalingPumpTask(deviceCode, id);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    /**
     * 除尘风机页面设备状态推送
     *
     * @return
     */

    @MessageMapping("/dedust_fan/{relationId}/{deviceCode}/{id}")
    public void dedustFan(@DestinationVariable(value = "relationId") String relationId,@DestinationVariable(value = "deviceCode") String deviceCode, @DestinationVariable(value = "id") String id) {
        try {
            cronSchedulerJob.startDedustFanTask(relationId,deviceCode, id);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    /**
     * 辊道监测
     */
    @MessageMapping("/roller/{deviceCode}/{id}")
    public void roller(@DestinationVariable(value = "deviceCode") String deviceCode, @DestinationVariable(value = "id") String id) {
        try {
            cronSchedulerJob.startRollerTask(deviceCode, id);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    /**
     * 辊轮监测
     */
    @MessageMapping("/wheel/{deviceCode}/{id}")
    public void wheel(@DestinationVariable(value = "deviceCode") String deviceCode, @DestinationVariable(value = "id") String id) {
        try {
            cronSchedulerJob.startWheelTask(deviceCode, id);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }


}